using System;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace pginstaller.tasks
{
    public class TranslationStatus : Task
    {
        /* List of files to include in the ZIP */
        [Required]
        public string[] Languages
        {
            get { return _languages; }
            set { _languages = value; }
        }

        /* Internal storage for the properties */
        private string[] _languages;
        
        /* Perform the actual build task */
        public override bool Execute()
        {
            Log.LogMessage("----- Current translation status -----");
            foreach (string lang in _languages)
            {
                int numstrings = 0;
                int numtranslated = 0;

                if (lang == "en")
                    continue;

                XmlReader rdr = XmlReader.Create(lang + ".xml");
                while (rdr.Read())
                {
                    if (rdr.Name == "string")
                    {
                        numstrings++;
                        if (rdr.GetAttribute("translation") != "")
                            numtranslated++;
                    }
                }
                rdr.Close();
                Log.LogMessage("{0}: {1} total strings, {2} translated ({3}%)",
                    lang, numstrings, numtranslated, numtranslated * 100 / numstrings);
            }

            return true;
       }
    }
}